Shader "Hidden/EyebrowMask"
{
    Properties
    {
        _IDMap ("ID Map", 2D) = "white" {}
        _Threshold ("Eyebrow Threshold", Range(0, 1)) = 0.5
    }
    
    SubShader
    {
        Tags { "RenderType"="Opaque" "Queue"="Geometry" }
        ZWrite Off
        ZTest Always
        Cull Off
        
        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            
            struct Attributes
            {
                float4 positionOS : POSITION;
                float2 uv : TEXCOORD0;
            };
            
            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float2 uv : TEXCOORD0;
            };
            
            TEXTURE2D(_IDMap);
            SAMPLER(sampler_IDMap);
            float _Threshold;
            
            Varyings vert(Attributes input)
            {
                Varyings output;
                output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
                output.uv = input.uv;
                return output;
            }
            
            float4 frag(Varyings input) : SV_Target
            {
                // 获取ID贴图的R通道
                float idMapR = SAMPLE_TEXTURE2D(_IDMap, sampler_IDMap, input.uv).r;
                
                // 黑色是眉毛区域，白色是皮肤区域
                // 当R值小于阈值时，视为眉毛区域(输出1)，否则视为皮肤区域(输出0)
                float eyebrowMask = step(idMapR, _Threshold);
                
                return float4(eyebrowMask, eyebrowMask, eyebrowMask, 1.0);
            }
            ENDHLSL
        }
    }
}